<template>
  <div>
    <span class="fs_13 color_fff">{{ weather }} </span>
  </div>
</template>

<script>
import { getAmapWeather } from '@/config/weather-api.js';

export default {
  name: "AmapTianQi",
  components: {},
  data() {
    return {
      weather: ''
    };
  },
  computed: {
    
  },
  watch: {
    
  },
  mounted() {
    this.getWeather()
  },
  methods: {
     // 获取牧户 List
     async getWeather() {
      let res = await getAmapWeather();

      //获取当前日期函数
      let date = new Date(),
      year = date.getFullYear(), //获取完整的年份(4位)
      month = date.getMonth() + 1, //获取当前月份(0-11,0代表1月)
      strDate = date.getDate() // 获取当前日(1-31)
      if (month < 10) month = `0${month}` // 如果月份是个位数，在前面补0
      if (strDate < 10) strDate = `0${strDate}` // 如果日是个位数，在前面补0
  
      let date_now = `${year}-${month}-${strDate}`

      var dt = new Date();
      var weekDay = ["星期日", "星期一", "星期二", "星期三", "星期四", "星期五", "星期六"];
      // console.log('获取高德地图天气 : ', res);
      this.weather = `
        ${date_now}，
        ${ ' '}${weekDay[dt.getDay()]}，
        天气: ${res.lives[0].weather}，
        气温: ${res.lives[0].humidity - 24} ℃ 
      ` 
    },
  }
};
</script>

<style scoped lang="less">
  .text { color: #fff; font-size: 22px; }
</style>
